<?php

namespace app\model;

use think\Model;

class FactoryApply extends Model
{
    const IS_DELETE_NO = 0;

    /**
     * @Description 根据id判断数据是否存在
     * @author: zj
     * @param int $user_id
     * @param int $id
     * @time 2024/03/29 11:06:45
     * @return false|mixed
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function checkIsExist(int $user_id,int $id)
    {
        $info = $this->field('id')
            ->where('user_id', $user_id)
            ->where('id', $id)
            ->where('delete_time', self::IS_DELETE_NO)
            ->find();
        if (!$info) {
            return false;
        }

        return $info['id'];
    }

    /**
     * @Description 判断猪厂是否存在
     * @author: zj
     * @param int $user_id
     * @param string $name
     * @time 2024/03/29 11:07:32
     * @return false|mixed
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function checkNameIsExist(int $user_id,string $name)
    {
        $info = $this->field('id')
            ->where('user_id', $user_id)
            ->where('name', $name)
            ->where('delete_time', self::IS_DELETE_NO)
            ->find();
        if (!$info) {
            return false;
        }

        return $info['id'];
    }


}